package news.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import news.entity.Admin;

public class AdminDaoImpl implements IAdminDao {
	Connection conn=null;
	PreparedStatement pstmt=null;
	ResultSet rs=null;
	
	public Admin adminLogin(String name, String pwd) {
		Admin admin=null;
		try {
			conn=DaoFactory.getConn();
			String sql="select * from tb_admin where adminname=? and adminpwd=?";
			pstmt=conn.prepareStatement(sql);
			pstmt.setString(1, name);
			pstmt.setString(2, pwd);
			rs=pstmt.executeQuery();
			
			if(rs.next()){
				admin=new Admin(rs.getInt("adminid"),
						rs.getString("adminname"),
						rs.getString("adminpwd"),
						rs.getInt("adminflag"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return admin;
	}

}
